﻿@using Kovan.Model.Entity.UserCenter;
@using Kovan.Library.Utils;
@using Kovan.Library.Extensions;
@using Kovan.Model.ViewModel;
@using Kovan.Model.ViewModel.UserCenter;
@{
    var list = Model as List<EMenu>;
    var parentList = list.Where(c => c.module.parent_id == 0);

    var AuthorityCodes = ViewBag.AuthorityCodes as List<EAuthorityCode>;
}
<style type="text/css">
    ul.rightTools
    {
        float: right;
        display: block;
    }
    ul.rightTools li
    {
        float: left;
        display: block;
        margin-left: 5px;
    }
</style>
<div class="pageContent" style="padding: 5px">
    <div class="panel" defh="40">
        <h1>
            导航菜单</h1>
        <div>
            <table id="module_nav" class="searchContent">
                <tr>
                    <td>
                        导航名称：<input type="text" name="name" />
                    </td>
                    <td>
                        &nbsp;&nbsp;排序：<input type="text" name="sort_order" />
                    </td>
                    <td>
                        &nbsp;&nbsp;
                    </td>
                    <td>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button id="module_nav_fastsave" type="button" key="module_nav_fastsave">
                                    快速保存</button></div>
                        </div>
                    </td>
                    <td>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                    <td>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button type="button" key="module_nav_edit">
                                    编辑导航</button></div>
                        </div>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button type="button" key="module_nav_add">
                                    添加导航</button></div>
                        </div>
                        <div class="buttonActive">
                            <div class="buttonContent">
                                <button type="button" key="module_nav_delete">
                                    删除导航</button></div>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    @*<div class="divider">
    </div>*@
    <div class="tabs">
        <div class="tabsHeader">
            <div class="tabsHeaderContent" id="tabs_module">
                <ul>
                    @foreach (var item in parentList)
                    {
                        <li><a href="javascript:;"><span  moduleid="@item.module.module_id" sort="@item.module.sort_order" key="module_tabs_click">@item.module.name</span></a></li>
                    }
                </ul>
            </div>
        </div>
        <div class="tabsContent">
            @foreach (var item in parentList)
            {
                <div class="module_content">
                    <div id="left_module" layouth="136" style="float: left; display: block; overflow: auto;
                        width: 240px; border: solid 1px #CCC; line-height: 21px; background: #fff">
                        @NodeItem(item, list)
                    </div>
                    <div style="margin-left: 246px;">
                        <div class="pageHeader" style="border: 1px #B8D0D6 solid">
                            <form method="post" action="@Url.Content("~/Module/SaveMenu")" class="pageForm required-validate"
                            onsubmit="return Manage_Module.SaveMenu_Edit(this, Manage_Module.navTabAjaxDone);">
                            <div class="pageFormContent" layouth="202">
                                <p>
                                    <label>
                                        菜单名称：</label>
                                    <input type="text" name="name" size="30" class="required" />
                                    <input type="hidden" name="application_id" />
                                    <input type="hidden" name="module_id" />
                                    <input type="hidden" name="authoritys" value="" />
                                </p>
                                <p>
                                    <label>
                                        排序：</label>
                                    <input type="text" name="sort_order" size="30" class="digits" alt="请输入数字" />
                                </p>
                                <p style="display: none;">
                                    <label>
                                        图标地址：</label>
                                    <input type="text" id="icon_url" name="" size="30" />
                                </p>
                                <p>
                                    <label>
                                        前端地址：</label>
                                    <input type="text" name="front_url" size="30" />
                                </p>
                                <p>
                                    <label>
                                        后台地址：</label>
                                    <input type="text" size="30" name="url" />
                                </p>
                                <p>
                                    <label>
                                        父级菜单：</label>
                                    <select name="parent_id">
                                        <option value="0">请选择</option>
                                        @foreach (var item2 in list)
                                        {
                                            <option value="@item2.module.module_id" @(item.module.module_id == item2.module.module_id ? "selected" : "")>@item2.name2</option>
                                        }
                                    </select>
                                </p>
                                <p>
                                    <label>
                                        前端菜单：</label>
                                    <input type="checkbox" checked="checked" name="is_menu" value="1" />
                                </p>
                                <p>
                                    <label>
                                        是否显示：</label>
                                    <input type="checkbox" checked="checked" name="is_view" value="1" />
                                </p>
                                <p>
                                    <label>
                                        是否激活：</label>
                                    <input type="checkbox" checked="checked" name="enabled" value="1" />
                                </p>
                                <dl class="nowrap" style="width: 98%">
                                    <dt>可选权限：</dt>
                                    <dd class="lab_none">
                                        @foreach (var authority in AuthorityCodes)
                                        {
                                            <label>
                                                <input type="checkbox" name="authority" value="@authority.code" />@authority.name&nbsp;</label>
                                        }
                                    </dd>
                                </dl>
                                <dl class="nowrap" style="width: 98%">
                                    <dt>页面参数：</dt>
                                    <dd>
                                        <textarea name="menu_params" cols="77" rows="5"></textarea></dd>
                                </dl>
                                <dl class="nowrap" style="width: 98%">
                                    <dt>描述：</dt>
                                    <dd>
                                        <textarea name="description" cols="77" rows="5"></textarea></dd>
                                </dl>
                            </div>
                            <div class="formBar">
                                <ul>
                                    @*<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>*@
                                    <li>@*<a class="buttonActive" href="javascript:;"><span>删除菜单</span></a>*@
                                        <div class="buttonActive">
                                            <div class="buttonContent">
                                                <button type="button" id="module_del" key="module_menu_delete" moduleid="" menuname="">
                                                    删除菜单</button></div>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="buttonActive">
                                            <div class="buttonContent">
                                                <button type="button" key="module_menu_add">
                                                    添加菜单</button></div>
                                        </div>
                                    </li>
                                    <li>&nbsp;&nbsp;&nbsp;</li>
                                    <li>
                                        <div class="buttonActive">
                                            <div class="buttonContent">
                                                <button type="submit">
                                                    保存</button></div>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="button">
                                            <div class="buttonContent">
                                                <button type="reset">
                                                    清空</button></div>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
            }
        </div>
        <div class="tabsFooter">
            <div class="tabsFooterContent">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="@Url.Content2("~/Scripts/Manage/Module/Index.js")"></script>
@helper NodeItem(EMenu menu, List<EMenu> list)
    {
        var list1 = list.Where(c => c.module.parent_id.Value == menu.module.module_id.Value);

        if (list1 != null && list1.Count() > 0)
        {
    @Html.Raw(string.Format("<ul class=\"{0}\">", menu.module.parent_id.Value == 0 ? "tree treeFolder treeCheck" : ""))
            foreach (var item in list1)
            {
                var list2 = list.Where(c => c.module.parent_id.Value == item.module.module_id.Value);
    @Html.Raw("<li>")
    @Html.Raw(string.Format("<a href=\"javascript:;\" tname=\"moduleid\" tvalue=\"{0}\" onclick=\"Manage_Module.ClickMenu(this,{0});\">{1}</a>", item.module.module_id, item.module.name))
                if (list2 != null && list1.Count() > 0)
                {
    @NodeItem(item, list)
                }
    @Html.Raw("</li>")
            }
    @Html.Raw("</ul>")
        }
}
